﻿
@using Kooboo.CMS.Content.Models;
@using Kooboo.CMS.Content.Query;
@if(Model==null)
{
    @("The content was deleted.".Localize())
}
else
{
    var schema = (Kooboo.CMS.Content.Models.Schema)ViewData["Schema"];
    var allowedEdit = (bool)ViewData["AllowedEdit"];
    var allowedView = (bool)ViewData["AllowedView"];
    var workflowItem  = Model._WorkflowItem_;
    var hasWorkflowItem = workflowItem!=null;
    var availableEdit = hasWorkflowItem || (!hasWorkflowItem && allowedEdit);

    using(Html.BeginForm(ViewContext.RequestContext.AllRouteValues()["action"].ToString()
            , ViewContext.RequestContext.AllRouteValues()["controller"].ToString()
            , ViewContext.RequestContext.AllRouteValues()
            , FormMethod.Post, new RouteValueDictionary(new { enctype = "application/x-www-form-urlencoded" })))
{
    <div class="common-form">
    <fieldset>
    <table><tr>
            <td>
            <label for="Title">Title</label>
            </td>
            <td>
            <input id="Title" name="Title" type="text" value="@(Model.Title ?? "")" />
            @Html.ValidationMessageForColumn(((ISchema)ViewData["Schema"])["Title"], null)
            </td>          
            </tr>
            @if (allowedEdit) {
                <tr>
            <td>
            <label for="Published">Published</label>
            </td>
            <td>
            <input name="Published" type="checkbox" @(Convert.ToBoolean(Model.Published)?"checked":"") value="true"/>
                                    <input type="hidden" value="false" name="Published"/>
            @Html.ValidationMessageForColumn(((ISchema)ViewData["Schema"])["Published"], null)
            </td>          
            </tr>
            }
    @Html.Action("Categories", ViewContext.RequestContext.AllRouteValues())
    </table>
    </fieldset>
     <p class="buttons">
        @if(availableEdit){
           <button type="submit">@("Save".Localize())</button>
            if(Model.IsLocalized !=null && Model.IsLocalized == false){<button type="submit" name="Localize" value="true">Localize</button>}            
            <a href="javascript:;" class="dialog-close button">@("Close".Localize())</a>            
        }
        else
        {
            <a href="javascript:;" class="dialog-close button">@("Close".Localize())</a>
            <a href="@Url.Action("WorkflowHistory","PendingWorkflow",ViewContext.RequestContext.AllRouteValues().Merge("UserKey", (object)(Model.UserKey)).Merge("UUID",(object)(Model.UUID)))" title="@("View workflow history".Localize())" class="button  dialog-link">@("View workflow history".Localize())</a>
            <a href="javascript:;" class="tooltip-link" title="@("The content is approving or you have not permission to publish.".Localize())"></a>
        }
       
     </p>
   </div>   
  }
}